-- gui.lua -> draw and manager the user interface

mmgui = {}

-- the menu are displayed at all screens
function mmgui:programMenu()
	menus = {"Registers",
		 "New register",
	         "Register Types",
		 "Graphics",
		 "Synchronize",
		 "About SDmm"}
	gui.menu(menus)
	gui.sethandler(menuSelect,generalControler)
end

function mmgui:aboutProgram()
	theScreen = "aboutProgram";
	gui.destroy()
	screen.clear()
	gui.title("About SDmm")
	mmgui:programMenu()

	text = "This program is a free sofware!\n"
	text = text.."Developer: Helton Eduardo Ritter\n"
	text = text.."Mail: heltonritter@gmail.com\n\n"
	text = text.."Blog: lua.sourcedreams.com.br\n"
	text = text.."Site: www.sourcedreams.com.br\n\n"
	text = text.."Thanks for use Source Dreams Money Manager!"

	
	gui.control{type="field", lines=11, columns=30, text=text}
	gui.nl()
	gui.tab()
	gui.control{type="button", text="Ok", handler=generalControler}

end



function mmgui:showRegisterTypes()
	gui.destroy()
	screen.clear()
	theScreen = "showRegisterTypes";
	gui.title("Your Register types")
	mmgui:programMenu()

	registers ={}
	registers[0]="O valor 1"
	registers[1]="O valor 2"
	registers[2]="O valor 3"
	registers[3]="O valor 4"

	gui.control{type="list", lines=11, columns=31, list=registers, handler=generalControler}
	gui.nl()
	gui.control{type="button", text="New type", handler=generalControler}
	

end


function mmgui:newRegisterType()
	gui.destroy()
	screen.clear()
	theScreen = "newRegisterType";
	gui.title("New Register type")
	mmgui:programMenu()

	gui.label("Register type:")
	gui.nl()
	gui.field(1,30,20)
	gui.nl()

	ch = gui.checkbox("Actived - appear on new register")
	gui.nl()
	
	gui.label("Default value:")
	gui.field(1,10,10)
	gui.nl()
	
	gui.nl()
	gui.control{type="button", text="Save type", handler=generalControler}
	
end

function mmgui:newRegister()	
	theScreen = "newRegister";
	gui.destroy()
	screen.clear()	
	gui.title("New Register")
	mmgui:programMenu()

	gui.label("Value:")
	gui.field(1,10,10)
	gui.nl()

	gui.label("Description:")
	gui.nl()
	gui.field(4,30,100)
	gui.nl()

-- PROBLEM HERE ----------------	
	gui.label("Type:")
	-- change HERE! must read this options for data file
        types = {"food",
	         "Whater",
		 "phone"}

	gui.control{type="popup", list=types, selected=1,handler=generalControler}
	gui.nl()
-- END of PROBLEM HERE ----------------


	gui.label("Date:")
	-- value sugestion: current date
	gui.field(1,10,10,os.date("%Y-%m-%d"))
	gui.control{type="button",text="calendar",handler=generalControler}
	
	gui.nl()

	gui.control{type="button",text="Save", handler=generalControler}
end


function mmgui:showGraphics()
	gui.destroy()
	screen.clear()
	theScreen = "showGraphics";
	gui.title("Graphics results")
	mmgui:programMenu()
	
	dta = {{"teste","value1"},{"nada","value2"},{"outro","mais"}}
	--dta[1] = {}
	--dta[0] ={}
	--dta[2] = {}

--	dta[0] = "Desc1"
	--dta[0][1] = "value1"
--	dta[1][0] = "Desc2"
--	dta[1]1] = "value2"
--	dta[2][1] = "Desc3"
--	dta[2][1] = "Value3"

	gui.list(20,30,dta)
end


function mmgui:syncDevice()
	theScreen = "syncDevice";
	gui.destroy()
	screen.clear()
	gui.title("Synchronize")
	mmgui:programMenu()
	gui.nl()
	gui.label("All data are be exported")
	gui.nl()
	gui.label("and send to other IRdata device.")
	gui.nl()
	gui.control{type="button", text="Send data >", handler=generalControler}
end





-- filter data to display in list on main screen

function mmgui:filterSelected()
	
end



function mmgui:mainScreen()
	gui.destroy()
	screen.clear()
	gui.title("SDmm")
	theScreen = "mainScreen";

	mmgui:programMenu()
	
	gui.label("Filter date on list: ")
	filtros = {"All",
		  "Current Week",
		  "Last Week",
		  "Last month",
		  "Date range",
		  "One date"}
  	gui.control{type="popup", list=filtros, selected=2,handler=generalControler}
	gui.nl()
	
	registers ={}
	registers[0]="O valor 1"
	registers[1]="O valor 2"
	registers[2]="O valor 3"
	registers[3]="O valor 4"
	registers[4]="O valor 4"
	registers[5]="O valor 4"
	registers[6]="O valor 4"
	registers[7]="O valor 4"
	registers[8]="O valor 4"
	registers[9]="O valor 4"

	gui.control{type="list", lines=10, columns=31, list=registers, handler=generalControler}
	gui.nl()
	gui.control{type="button", text="New register", handler=generalControler}
	gui.label("My money:")
	gui.label("R$ 00,00")
	
end

